﻿using System;
using System.Web;

namespace NWebMock
{
    public class HttpCachePolicyWrapper : IHttpCachePolicy
    {
        #region Constructors

        public HttpCachePolicyWrapper(HttpCachePolicy cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            this.innerCache = cache;
        }

        #endregion

        #region Fields

        private HttpCachePolicy innerCache = null;
        private IHttpCacheVaryByContentEncodings innerVaryByContentEncodings = null;
        private IHttpCacheVaryByHeaders innerVaryByHeaders = null;
        private IHttpCacheVaryByParams innerVaryByParams = null;

        #endregion

        #region Properties

        public IHttpCacheVaryByContentEncodings VaryByContentEncodings
        {
            get
            {
                if (this.innerVaryByContentEncodings != null)
                {
                    return this.innerVaryByContentEncodings;
                }

                if (this.innerCache.VaryByContentEncodings!=null)
                {
                    this.innerVaryByContentEncodings = new HttpCacheVaryByContentEncodingsWrapper(this.innerCache.VaryByContentEncodings);
                    return this.innerVaryByContentEncodings;
                }

                return null;
            }
        }

        public IHttpCacheVaryByHeaders VaryByHeaders
        {
            get
            {
                if (this.innerVaryByHeaders != null)
                {
                    return this.innerVaryByHeaders;
                }

                if (this.innerCache.VaryByHeaders != null)
                {
                    this.innerVaryByHeaders = new HttpCacheVaryByHeadersWrapper(this.innerCache.VaryByHeaders);
                    return this.innerVaryByHeaders;
                }

                return null;
            }
        }

        public IHttpCacheVaryByParams VaryByParams
        {
            get
            {
                if (this.innerVaryByParams != null)
                {
                    return this.innerVaryByParams;
                }

                if (this.innerCache.VaryByParams != null)
                {
                    this.innerVaryByParams = new HttpCacheVaryByParamsWrapper(this.innerCache.VaryByParams);
                    return this.innerVaryByParams;
                }

                return null;
            }
        }

        #endregion

        #region Methods

        public void AddValidationCallback(HttpCacheValidateHandler handler, object data)
        {
            this.innerCache.AddValidationCallback(handler, data);
        }

        public void AppendCacheExtension(string extension)
        {
            this.innerCache.AppendCacheExtension(extension);
        }

        public void SetAllowResponseInBrowserHistory(bool allow)
        {
            this.innerCache.SetAllowResponseInBrowserHistory(allow);
        }

        public void SetCacheability(HttpCacheability cacheability)
        {
            this.innerCache.SetCacheability(cacheability);
        }

        public void SetCacheability(HttpCacheability cacheability, string field)
        {
            this.innerCache.SetCacheability(cacheability, field);
        }

        public void SetETag(string etag)
        {
            this.innerCache.SetETag(etag);
        }

        public void SetETagFromFileDependencies()
        {
            this.innerCache.SetETagFromFileDependencies();
        }

        public void SetExpires(DateTime date)
        {
            this.innerCache.SetExpires(date);
        }

        public void SetLastModified(DateTime date)
        {
            this.innerCache.SetLastModified(date);
        }

        public void SetLastModifiedFromFileDependencies()
        {
            this.innerCache.SetLastModifiedFromFileDependencies();
        }

        public void SetMaxAge(TimeSpan delta)
        {
            this.innerCache.SetMaxAge(delta);
        }

        public void SetNoServerCaching()
        {
            this.innerCache.SetNoServerCaching();
        }

        public void SetNoStore()
        {
            this.innerCache.SetNoStore();
        }

        public void SetNoTransforms()
        {
            this.innerCache.SetNoTransforms();
        }

        public void SetOmitVaryStar(bool omit)
        {
            this.innerCache.SetOmitVaryStar(omit);
        }

        public void SetProxyMaxAge(TimeSpan delta)
        {
            this.innerCache.SetProxyMaxAge(delta);
        }

        public void SetRevalidation(HttpCacheRevalidation revalidation)
        {
            this.innerCache.SetRevalidation(revalidation);
        }

        public void SetSlidingExpiration(bool slide)
        {
            this.innerCache.SetSlidingExpiration(slide);
        }

        public void SetValidUntilExpires(bool validUntilExpires)
        {
            this.innerCache.SetValidUntilExpires(validUntilExpires);
        }

        public void SetVaryByCustom(string custom)
        {
            this.innerCache.SetVaryByCustom(custom);
        }

        #endregion
    }
}
